package com.mxnavi5.example.DataStream;


import org.apache.flink.api.common.functions.AggregateFunction;
import org.apache.flink.api.java.tuple.Tuple2;

public class MyAggFunction implements AggregateFunction<Integer, Tuple2<Integer,Integer>, Integer> {

    @Override
    public Tuple2<Integer,Integer> createAccumulator() {
        return Tuple2.of(0,0);
    }

    @Override
    public Tuple2<Integer,Integer> add(Integer i, Tuple2<Integer,Integer> acc) {
        return Tuple2.of(acc.f0+i,acc.f1+1);
    }

    @Override
    public Integer getResult(Tuple2<Integer,Integer> acc ) {
        System.out.println("acc："+acc);
        return acc.f0/ acc.f1;
    }

    @Override
    public Tuple2<Integer,Integer>  merge(Tuple2<Integer,Integer> acc1, Tuple2<Integer,Integer> acc2 ) {
        return null;
    }
}
